#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   run.py
@Time    :   2020/09/26 16:19:26
@Author  :   fengzhilaoling 
@Version :   1.0
@EMAIL :   fengzhilaoling@163.com
'''

from flask import Flask
from flask import Response
from flask import request
from flask import make_response
from datetime import datetime
from datetime import timedelta
app = Flask(__name__)

@app.route('/index/')
def index():
    response = Response("设置cookie")
    response.set_cookie('username', 'fengzhilaoling')  # 设置cookie
    response.set_cookie('password', '123', max_age=60)  # max_age设置多少秒后过期
    expires = datetime.now() + timedelta(days=30, hours=16)  # 设置当前时间加上多长时间
    # flask中cookies会自动增加8小时，所以这里的31天就是：30天 + 16小时 + 自动增加的8小时
    response.set_cookie('time', '31', expires=expires)
    return response


@app.route('/get_index/')
def get_index():
    username = request.cookies.get('username')  # 查看cookie
    return username


@app.route('/delete_index/')
def delete_index():
    response = make_response('delete cookies')  # 删除cookie
    response.delete_cookie('username')
    return response

if __name__ == '__main__':
    app.run()